package com.anXin.user.controller;


import com.anXin.model.common.dtos.ResponseResult;
import com.anXin.model.user.dtos.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import com.anXin.user.service.UserService;
import utils.thread.AppThreadLocalUtil;

import javax.annotation.Resource;

@Api(tags = "用户登录注册接口" )
@RestController
@RequestMapping("/app/login")
public class UserLoginController {

    @Resource
    private UserService userService;

    @ApiOperation("手机号密码登录")
    @PostMapping("/login_auth")
    public ResponseResult login(@RequestBody LoginDto dto) {
        return userService.login(dto);
    }

    @ApiOperation("手机号验证码登录")
    @PostMapping("/login_phone")
    public ResponseResult loginByPhone(@RequestBody LoginByPhoneDto dto) {
        return userService.loginByPhone(dto);
    }


    @ApiOperation("手机号注册")
    @PostMapping("/reg")
    public ResponseResult reg(@RequestBody RegDto dto) {
        return userService.reg(dto);
    }


    @ApiOperation("获取手机号验证码")
    @PostMapping("/phoneCode")
    public ResponseResult phoneCode(@RequestBody PhoneCodeDto dto) {
        return userService.phoneCode(dto);
    }

    /**
     * 检查验证码
     * @param dto
     * @return
     */
    @PostMapping("/checkPhoneCode")
    public ResponseResult checkPhoneCode(@RequestBody LoginByPhoneDto dto) {
        return userService.checkPhoneCode(dto);
    }

    /**
     * 修改密码
     * @param dto
     * @return
     */
    @PutMapping("/updatePassword")
    public ResponseResult updatePassword(@RequestBody UpdateDto dto) {
        return userService.updatePassword(dto);
    }


    @ApiOperation("登出")
    @PostMapping("/logout")
    public ResponseResult logout(){
        AppThreadLocalUtil.clear();
        return ResponseResult.okResult("退出账号成功");
    }
}